package com.wxfire;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping
public class JSONAndXmlDemo {

    @RequestMapping(value = "json", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object json2() {
        JsonResult map = new JsonResult();
        map.code = "0";
        map.data="hello";
        return map;
    }

    @RequestMapping(value = "xml", produces = MediaType.APPLICATION_XML_VALUE)
    public Object xml() {
        XmlResult map = new XmlResult();
        map.code = "0";
        map.data="hello";
        return map;
    }


}

@JacksonXmlRootElement
class XmlResult {
    @JacksonXmlProperty(localName = "code")
    String code;
    @JacksonXmlProperty(localName = "data")
    String data;
}

class JsonResult  {
    public String code;
    public String data;
}
